<?php ?>
<div class="row-fluid">
<div class="span8">
<header id="proposal"> Select Proposal </header>
   <div class="input-append">
   <form method="post"action="<?= site_url('user/proposal/view_proposal');?>">
    <select id="proposaldelete" name="proposaldelete">
	   <option value="">Select Proposal</option>
      <?php foreach($proposal as $row){?> 
     <option value="<?php echo $row->id;?>"><?php echo $row->proposal_name;?></option>
	 <?php }?></select>

<div class="btn-group pointer">
<button class="btn dropdown-toggle" data-toggle="dropdown">
Action
<span class="caret"></span>
</button>
<ul class="dropdown-menu pointer">

 <li> <button type="submit" class="btn btn-link " name="preview"> view </button></li></form>
<li > <button type ="button" class="btn btn-link" onclick="deleteproposal()";>Delete</button></li>

</ul>
</div>
</div> 
<header id="category"> Select Plan </header>
   <div class="input-append">
    <select id="categorys">
	   <option value="">Select Plan Type</option>
      <?php foreach($category as $categories){?> 
     <option value="<?php echo $categories->id;?>"><?php echo $categories->name;?></option>
	 <?php }?></select>

<div class="btn-group pointer">
<button class="btn dropdown-toggle" data-toggle="dropdown">
Action
<span class="caret"></span>
</button>
<ul class="dropdown-menu pointer">
<li onclick="getallmodule()";><a> View</a></li>
<li onclick="deletecategory()";><a> Delete</a></li>
</ul>
</div>
</div> 
	<header>Module and Features</header>
    <div class="accordion" id="accordion">
  </div>
  </div>
<div class="span4">
 <header id="proposalheader" class="pointer">Create Your Proposal</header>
<div id="headerproposal">
<table width="100%" class="">
<tr>
    <form method="post" action="<?= site_url('user/proposal/proposal_preview');?>">
	
    <td>Your Name</td>
    <td><input type="text" name="user_name" class="user_name" /></td>
  </tr>
  <tr>
    <td>Company Name:</td>
    <td><input type="text" name="user_company" class="user_company" /></td>
  </tr>
  <tr>
    <td>Your Address:</td>
    <td><address><textarea name="user_address" class="user_address" > </textarea></address></td>
  </tr>
  <tr>
    <td>Client Name</td>
    <td><input type="text" name="client_names" class="client_name" /></td>
  </tr>
  <tr>
    <td>Client Address</td>
    <td> <address><textarea name="client_addresss" class="client_address"></textarea></address></td>
  </tr>
  <tr>
    <td>Select Category</td>
    <td><select id="proposal_category" class="proposal_category" name="proposal_category" >
	<option value="">Select Category Type</option>
     <?php foreach($category as $row){
     $id= $row->id; 
     $name= $row->name; 
 echo "<option value=$id>$name </option>";}?>
     </select> </td>
  </tr>
  <tr>
    <td>Proposal Name</td>
    <td><input type="text" name="proposal_name" class="proposal_name" /></td>
  </tr>
  <tr>
    <td>Proposal Description</td>
    <td><textarea name="proposal_desc" class="proposal_desc"> </textarea></td>
  </tr>
   <tr>
    <td>&nbsp;</td>
    <td><input type="button" class="btn btn-success" id="create-proposal" value="Create Proposal" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
	<input type="submit" class="btn btn-success" id="create-proposalpreview" value="Preview" name="preview" />
	</td>
  </tr></form>
  </table></div>
<header id="categoryheader" class="pointer">Create Category</header>
<div id="headercategory">
<table width="100%" class="">
  <tr>
    <td>Name</td>
    <td><input type="text" name="categoryname" class="category_name" /></td>
  </tr>
  <tr>
    <td>Description</td>
    <td><textarea  id="categorydesc" class="category_desc"></textarea></td>
	<script type="text/javascript">
        CKEDITOR.replace( 'categorydesc' );
      </script>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td><input type="button" class="btn btn-success" id="create-category" value="Create Category" /></td>
  </tr>
  </table></div>
 <header id="sectionheader" class="pointer">Create Section</header>
<div id="headersection">
<table width="100%" class="">
  <tr>
    <td>Name</td>
    <td><input type="text" name="categoryname" class="section_name" /></td>
  </tr>
  <tr>
    <td>Position</td>
    <td>
	<select class="section_position" >
        <option value="header">Header</option>
        <option value="body">Body</option>
         <option value="footer">Footer</option>
     </select>
</td>
  </tr>
  <tr>
    <td>Select Category</td>
    <td><select id="section_category" class="section_category" >
     <?php foreach($category as $row){
     $id= $row->id; 
     $name= $row->name; 
 echo "<option value=$id>$name </option>";}?>
     </select> </td>
  </tr>
   <tr>
    <td>&nbsp;</td>
    <td><input type="button" class="btn btn-success" id="create-section" value="Create Section" /></td>
  </tr>
  </table></div>
<header id="moduleheader" class="pointer">Create Module</header>
<div id="headermodule">
<table width="100%" class="">
    <tr>
    <td>Select Category</td>
    <td><select id="module_category" class="module_category" onchange="callsection()";>
	<option> Select</option>
     <?php foreach($category as $section){
     $id= $section->id; 
     $name= $section->name; 
     echo "<option value=$id>$name </option>";}?>
     </select> </td>
  </tr>
   <tr>
    <td>Select Section</td>
    <td><select id="module_section" class="module_section" >
     
     </select> </td>
  </tr>
  <tr>
    <td>Name</td>
    <td><input type="text" name="name" class="module_name" /></td>
  </tr>
  <tr>
    <td>Description</td>
    <td><textarea  id="moduldesc" class="module_desc"></textarea></td>
	<script type="text/javascript">
        CKEDITOR.replace( 'moduldesc' );
      </script>
  </tr>
  <tr>
    <td>Price</td>
    <td>
    <div class="input-prepend">
  <span class="add-on">Rs</span>
  <input class="span6 module_price" id="prependedInput" type="text" placeholder="price">
</div>
    </td>
  </tr>
  <tr>
    <td>Time Required</td>
    <td>
    <div class="input-prepend">
  <span class="add-on">Days</span>
  <input class="span6 module_days" id="prependedInput" type="text" placeholder="Days ">
</div>
    </td>
  </tr>
   <tr>
    <td>&nbsp;</td>
    <td><button class="btn btn-success" id="create-module">Create Module</button></td>
  </tr>
</table></div>
<header id="headerfeature" class="pointer">Create Features</header>
<div id="featureheader">
<table width="100%">
 <tr>
    <td>Select Category</td>
    <td><select id="features_category" class="features_category" onchange="get_module()";>
	<option> Select</option>
     <?php foreach($category as $categ){
     $id= $categ->id; 
     $name= $categ->name; 
     echo "<option value=$id>$name </option>";}?>
     </select> </td>
  </tr>
  <tr>
    <td>Select Module</td>
    <td><select class="feature_type" id="features_module">
	<option value="">Select Module Type</option>
	<option> Select</option>
     
     </select> </td>
  </tr>
  <tr>
    <td>Name</td>
    <td><input type="text" name="name" class="feature_name" /></td>
  </tr>
  <tr>
    <td>Description</td>
    <td><textarea  id="featdesc" class="feature_desc"></textarea></td>
	<script type="text/javascript">
        CKEDITOR.replace( 'featdesc' );
      </script>
  </tr>
  <tr>
    <td>Price</td>
    <td>
    <div class="input-prepend">
  <span class="add-on">Rs</span>
  <input  id="prependedInput" type="text" placeholder="price" class="feature_price span6 module_price" >
</div>
    </td>
  </tr>
 
  <tr>
    <td>&nbsp;</td>
    <td><input type="submit" class="btn btn-success" id="create-feature" value="Create Feature" /></td>
  </tr>
</table></div>
</div>
</div>
<script type="text/javascript">
//for proposal
$('#create-proposal').click(function () {	
	if(!$('.user_name').val())
	{alert('Name Feild is Required');	
		$('.user_name').focus();}
	else if(!$('.user_company').val())
	{alert('Company Feild is Required');	
		$('.user_company').focus();}
	else if(!$('.user_address').val())
	{alert('Address Feild is Required');	
		$('.user_address').focus();}
	else if(!$('.client_name').val())
	{alert('Client Name Feild is Required');	
		$('.client_name').focus();}
	else if(!$('.client_address').val())
	{alert('Client Address Feild is Required');	
		$('.client_address').focus();}
	else if(!$('.proposal_category').val())
	{alert('Category Feild is Required');	
		$('.proposal_category').focus();}
	else if(!$('.proposal_name').val())
	{alert('Proposal Name Feild is Required');	
		$('.proposal_name').focus();}
	else if(!$('.proposal_desc').val())
	{alert('Description Feild is Required');	
		$('.proposal_desc').focus();}
	else {
	var user_name          =$('.user_name').val();
	var user_company       =$('.user_company').val();
	var user_address       =$('.user_address').val();
	var client_name        =$('.client_name').val();
	var client_address     =$('.client_address').val();
	var proposal_name      =$('.proposal_name').val();
	var proposal_category  = $('.proposal_category').val();
    var proposal_desc      =$('.proposal_desc').val();
	$.post('<?= site_url('user/proposal/create_proposal');?>',{user_name : user_name , user_company:user_company,user_address:user_address,client_name:client_name,client_address:client_address,proposal_name:proposal_name,proposal_category:proposal_category,proposal_desc:proposal_desc}, function(data) {
	 $('.category_name').val("");
	 $('.category_desc').val("");
	  location.reload();  });}})
//for category
$('#create-category').click(function () {	
	if(!$('.category_name').val())
	{alert('Name Feild is Required');	
		$('.category_name').focus();}
	else if(!CKEDITOR.instances.categorydesc.getData())
	{alert('Description Feild is Required');	
		$('.category_desc').focus();}
	else {var category_name = $('.category_name').val();
	var category_desc = CKEDITOR.instances.categorydesc.getData();
	$.post('<?= site_url('user/proposal/create_category');?>',{category_name : category_name , category_desc : category_desc}, function(data) {
	 $('.category_name').val(""); $('.category_desc').val("");  location.reload();  });}})
	//FOR SECTION
	$('#create-section').click(function () {	
	if(!$('.section_name').val())
	{alert('Name Feild is Required');	
		$('.section_name').focus();}
	else {var section_name = $('.section_name').val();var section_position=$('.section_position').val();var section_category=$('#section_category').val();
	$.post('<?= site_url('user/proposal/create_section');?>',{section_name : section_name , section_position: section_position, section_category:section_category}, function(data) {
	$('.section_name').val("");$('.section_position').val(""); $('.section_category').val("");location.reload(); });}})
//for module
$('#create-module').click(function () {	
	if(!$('.module_name').val())
	{alert('Name Feild is Required');	
		$('.module_name').focus();}
	else if(!CKEDITOR.instances.moduldesc.getData())
	{alert('Description Feild is Required');	
		$('.module_desc').focus();}
	else if(!$('.module_price').val())
	{alert('Price Feild is Required');	
		$('.module_price').focus();}
	else if(!$('.module_days').val())
	{alert('Price Feild is Required');	
		$('.module_days').focus();}
	else if(!$('.module_section').val())
	{alert('Type Feild is Required');	
	$('.module_type').focus();}
	else {
	var module_name = $('.module_name').val();
	var module_desc = CKEDITOR.instances.moduldesc.getData();
	var module_price = $('.module_price').val();
	var module_days = $('.module_days').val();
	var module_type = $('.module_section').val();
	$.post('<?= site_url('user/proposal/create_module');?>',{module_name : module_name , module_desc : module_desc ,module_days:module_days, module_price : module_price, module_type : module_type}, function(data) {
	 $('.module_name').val("");
	 $('.module_desc').val("");
	 $('.module_price').val("");
	 $('.module_type').val("");
	  location.reload();  });}})
	// for features
	
	$('#create-feature').click(function () {	
	if(!$('.feature_name').val())
	{alert('Name Feild is Required');	
		$('.feature_name').focus();}
	else if(!CKEDITOR.instances.featdesc.getData())
	{alert('Description Feild is Required');	
		$('.feature_desc').focus();}
	else if(!$('.feature_price').val())
	{alert('Price Feild is Required');	
		$('.feature_price').focus();}
	else if(!$('.feature_type').val())
	{alert('Type Feild is Required');	
	$('.feature_type').focus();}
	else {
	var feature_name = $('.feature_name').val();
	var feature_desc = CKEDITOR.instances.featdesc.getData();
	var feature_price = $('.feature_price').val();
	var feature_type = $('.feature_type').val();
	$.post('<?= site_url('user/proposal/create_feature');?>',{feature_name : feature_name , feature_desc : feature_desc , feature_price : feature_price, feature_type : feature_type}, function(data) {
	 $('.feature_name').val("");
	 $('.feature_desc').val("");
	 $('.feature_price').val("");
	 $('.feature_type').val("");
	  location.reload();  });}})
	</script>
<script>
$(document).ready(function(){
$("#headermodule").hide();
$("#headerproposal").hide();
$("#headersection").hide();
$("#featureheader").hide();
$("#headercategory").hide();
$("#proposalheader").click(function(){$("#headerproposal").slideToggle("slow");});
$("#categoryheader").click(function(){$("#headercategory").slideToggle("slow");});
$("#sectionheader").click(function(){$("#headersection").slideToggle("slow");});
$("#moduleheader").click(function(){$("#headermodule").slideToggle("slow");});
$("#headerfeature").click(function(){$("#featureheader").slideToggle("slow");});});
function callsection()
	{var proid = $('#module_category').val();var postData = {'proid':proid};
	  $.ajax({type: "POST",url:'<?= site_url('user/proposal/get_section');?>',
	 dataType:'html', data: postData,success: function(data){ document.getElementById('module_section').innerHTML = data; }})}
 function get_module()
	{var proid = $('#features_category').val();var postData = {'proid':proid};
	  $.ajax({type: "POST",url:'<?= site_url('user/proposal/get_module');?>',
	 dataType:'html', data: postData,success: function(data){ document.getElementById('features_module').innerHTML = data; }})}
 function getallmodule()
	{var proid = $('#categorys').val();var postData = {'proid':proid};
	  $.ajax({type: "POST",url:'<?= site_url('user/proposal/getallmodule');?>',
	 dataType:'html', data: postData,success: function(data){ document.getElementById('accordion').innerHTML = data; }})}
 function deletemodule(id)
	 {var id = id;var postData = {'id':id};
	  $.ajax({type: "POST",url:'<?= site_url('user/proposal/deletemodule');?>',
	  data: postData,
	   success: function(data){  alert(" Module Deleted "); window.location.reload()}}); }  
function deletefeature(id)
	 {var id = id;var postData = {'id':id};
	  $.ajax({type: "POST",url:'<?= site_url('user/proposal/deletefeature');?>',
	  data: postData,
	   success: function(data){  alert(" Features Deleted "); window.location.reload()}}); }  
function deletecategory()
	   {var id = $('#categorys').val();
	   var postData = {'id':id};
		$.ajax({type: "POST",url:'<?= site_url('user/proposal/deletecategory');?>',
		data: postData,
	   success: function(data){  alert(" Selected Category Deleted "); window.location.reload()}}); } 
 function deleteproposal()
	 {var id = $('#proposaldelete').val();
	 var postData = {'id':id};
	  $.ajax({type: "POST",url:'<?= site_url('user/proposal/deleteproposal');?>',
	  data: postData,
	   success: function(data){  alert(" Selected Proposal Deleted "); window.location.reload()}}); }  
function viewproposal()
	 {var id = $('#proposaldelete').val();
	 var postData = {'id':id};
	  $.ajax({type: "POST",url:'<?= site_url('user/proposal/viewproposal');?>',
	  data: postData,
	   success: function(data){ }}); }  
 
</script>



